Skip to content

Conversation

@dimbleby
Copy link
Contributor

Here's some sample code approximating the poetry code:

#!/usr/bin/env python3


def one() -> int:
    return 1


def two() -> int:
    return 2


def three() -> int:
    return 3


factories = [one, two, three]

registered = []
for factory in factories:
    registered.append(lambda: factory())

for registered_factory in registered:
    print(f"result is {registered_factory()}")

output is

result is 3
result is 3
result is 3

which is exactly the gotcha that flake8-bugbear's B023 was trying to warn about.

I've applied one of the workarounds that various parts of the internet recommend, and you can verify for yourself if you're so inclined that doing the same in the toy script gives the expected output.

@dimbleby
Copy link
Contributor Author

Although come to think of it this particular case could surely be more compactly fixed by not lambda-ing at all, register_factory(command.name, command) should do the job

@dimbleby
Copy link
Contributor Author

I've pushed the more compact fix in a second commit so that this discussion, such as it is, still makes sense. Feel free to squash if and when merging.

neersighted
neersighted previously approved these changes Aug 31, 2022
@neersighted neersighted merged commit 113f9fa into python-poetry:master Aug 31, 2022
@dimbleby dimbleby deleted the b023-is-real branch August 31, 2022 19:13
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants